// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database();
const errorCllection = db.collection('errors');

// 新增一条记录
function addRecord (data) {
  let date = new Date().getTime()+28800000
  date = new Date(date)
  return errorCllection.add({
    data: {
      ...data,
      createTime: '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()+ ' ' + date.getHours() + ":" + date.getMinutes()
    }
  });
}

// 云函数入口函数
exports.main = async (event, context) => {
  await addRecord(event);
  return true;
}